 //EFI controller
#ifndef __BUILD_TYPE__
#define __BUILD_TYPE__ (0)
#warning __BUILD_TYPE__ (0)
#endif

#ifndef PROTEUS_SIM
#define PROTEUS_SIM (0)
#warning PROTEUS_SIM is not defined
#endif

#if ((1 > __BUILD_TYPE__) || 3 < __BUILD_TYPE__)
#warning !!! Not defined build !!!
#warning __BUILD_TYPE__ (1) --- efi old
#warning __BUILD_TYPE__ (2) --- efi v2
#warning __BUILD_TYPE__ (3) --- dysplay i2c
#endif

#if (1 ==  __BUILD_TYPE__)
#warning Building ... old efi
#elif(2 ==  __BUILD_TYPE__)
#warning Building ... efi v2
#elif(3 ==  __BUILD_TYPE__)
#warning Building ... dysplay i2c
#else
#error !!! Not defined build !!!
#endif

#if ((1 ==  __BUILD_TYPE__) || (3 ==  __BUILD_TYPE__))
#include "P18F2525_ed.h"
  #if (3 ==  __BUILD_TYPE__)
    #DEVICE HIGH_INTS = TRUE
  #endif
#elif(2 ==  __BUILD_TYPE__)
#include "18F4620.h"
#else
#error !!! Not defined build !!!
#endif

//============== Type of run ===========================
#if ((1 ==  __BUILD_TYPE__) || 2 ==  __BUILD_TYPE__))
 #if (1 == PROTEUS_SIM)
    #define     BURN_DISABLE
    #define     OPT_LEVEL
    #define     USE_PLL         (1)
    #define     ADC_SYNCH               //synchronisation for main loop with adc conversoin interrupt program
    #define     TMR0_16B        (1)     // tmr0 16-bit mode
    #define     IGN_DEBUG       (1)     //debug hall sensor settings
    #define     ACTIVE_PULSE    (0)     //inverted - active tcho pulse front (fuel inject event)
    #define     MS_STATES       (0)     //enable set/clear cranking bit in engine status byte
    #define     DEBUG_TABLES    (0)     //debug inerpolation with ms an others
    #define     TRACE           (0)     //trace enable / disable
    #define     RPM_MAP_INDEX   (1)     //use index table for map/rpm
    #define     DEBUG_INT_2D    (0)     //debug
    #define     INT_2D_MAP_BATT (0)     //use interpolation for batt and map
    #define     DEBUG_START_UP  (0)     //debug satrtup on hardware
    #define     ENABLE_I2C_COMM (0)     //disable i2c calls
    #define     I2C_PACK_SIZE   (20)    //size of data that will be trasfered at once over I2C inteface
    #define     I2C_ADR_SIZE    (2)     //size of address data
    #define     USE_AUTO_TUNE   (1)     //use auto tinig from megasquirt
    #define     DBG_PUTS_EN     (0)     //enable puts trace
  #elif (0 == PROTEUS_SIM)
    #define     USE_PLL         (1)
    #define     ADC_SYNCH               //synchronisation for main loop with adc conversoin interrupt program
    #define     TMR0_16B        (1)     // tmr0 16-bit mode
    #define     IGN_DEBUG       (1)     //debug hall sensor settings
    #define     ACTIVE_PULSE    (0)     //inverted - active tcho pulse front (fuel inject event)
    #define     MS_STATES       (0)     //enable set/clear cranking bit in engine status byte
    #define     DEBUG_TABLES    (0)     //debug inerpolation with ms an others
    #define     TRACE           (0)     //trace enable / disable
    #define     RPM_MAP_INDEX   (1)     //use index table for map/rpm
    #define     DEBUG_INT_2D    (0)     //debug
    #define     INT_2D_MAP_BATT (0)     //use interpolation for batt and map
    #define     DEBUG_START_UP  (0)     //debug satrtup on hardware
    #define     ENABLE_I2C_COMM (1)     //disable i2c calls
    #define     I2C_PACK_SIZE   (20)    //size of data that will be trasfered at once over I2C inteface
    #define     I2C_ADR_SIZE    (1)     //size of address data
    #define     USE_AUTO_TUNE   (1)     //use auto tinig from megasquirt
    #define     DBG_PUTS_EN     (0)     //enable puts trace
  #else
    #error PROTEUS_SIM out of range !!!
  #endif
#elif(3 ==  __BUILD_TYPE__)
  #if (1 == PROTEUS_SIM)
    #define     BURN_DISABLE
    #define     OPT_LEVEL
    #define     USE_PLL         (0)
    //#define     ADC_SYNCH               //synchronisation for main loop with adc conversoin interrupt program
    #define     TMR0_16B        (1)     // tmr0 16-bit mode
    #define     IGN_DEBUG       (1)     //debug hall sensor settings
    #define     ACTIVE_PULSE    (0)     //inverted - active tcho pulse front (fuel inject event)
    #define     MS_STATES       (0)     //enable set/clear cranking bit in engine status byte
    #define     DEBUG_TABLES    (0)     //debug inerpolation with ms an others
    #define     TRACE           (0)     //trace enable / disable
    #define     RPM_MAP_INDEX   (1)     //use index table for map/rpm
    #define     DEBUG_INT_2D    (0)     //debug
    #define     INT_2D_MAP_BATT (0)     //use interpolation for batt and map
    #define     DEBUG_START_UP  (0)     //debug satrtup on hardware
    #define     ENABLE_I2C_COMM (0)     //disable i2c calls
    #define     I2C_PACK_SIZE   (20)    //size of data that will be trasfered at once over I2C inteface
    #define     I2C_ADR_SIZE    (2)     //size of address data
    #define     DBG_PUTS_EN     (0)     //enable puts trace
  #elif (0 == PROTEUS_SIM)
    #define     USE_PLL         (0)
    //#define     ADC_SYNCH               //synchronisation for main loop with adc conversoin interrupt program
    #define     TMR0_16B        (1)     // tmr0 16-bit mode
    #define     IGN_DEBUG       (1)     //debug hall sensor settings
    #define     ACTIVE_PULSE    (0)     //inverted - active tcho pulse front (fuel inject event)
    #define     MS_STATES       (0)     //enable set/clear cranking bit in engine status byte
    #define     DEBUG_TABLES    (0)     //debug inerpolation with ms an others
    #define     TRACE           (0)     //trace enable / disable
    #define     RPM_MAP_INDEX   (1)     //use index table for map/rpm
    #define     DEBUG_INT_2D    (0)     //debug
    #define     INT_2D_MAP_BATT (0)     //use interpolation for batt and map
    #define     DEBUG_START_UP  (0)     //debug satrtup on hardware
    #define     ENABLE_I2C_COMM (0)     //disable i2c calls
    #define     I2C_PACK_SIZE   (20)    //size of data that will be trasfered at once over I2C inteface
    #define     I2C_ADR_SIZE    (1)     //size of address data
    #define     DBG_PUTS_EN     (0)     //enable puts trace
  #else
    #error PROTEUS_SIM out of range !!!
  #endif
#else
#error !!! Not defined build !!!
#endif

#ifndef OPT_LEVEL
    #opt 11
#else
    #opt 5
#endif

#ifndef ADC_SYNCH
    #warning "ADC_SYNCH is not enabled"
#endif

#if (1 == I2C_ADR_SIZE)
    #warning "I2C address size is 8 bit"
#elif (2 == I2C_ADR_SIZE)
    #warning  "I2C address size is 16 bit"
#else
    #error "Out of range"
#endif

#if (0 == TMR0_16B)
    #warning "TMR0_16B is not used"
#endif

#if (1 == IGN_DEBUG)
    #warning "IGN_DEBUG is enabled"
#endif

#if (1 == DEBUG_TABLES)
    #warning "DEBUG_TABLES is enabled"
#endif

#if (1 == TRACE)
    #warning "TRACE is enabled"
#endif

#if (1 == RPM_MAP_INDEX)
    #warning "RPM_MAP_INDEX is enabled OK"
#endif

#if (1 == DEBUG_INT_2D)
    #warning "DEBUG_INT_2D is enabled"
#endif

#if (1 == INT_2D_MAP_BATT)
    #warning "INT_2D_MAP_BATT is enabled"
#endif

#if (1 == DEBUG_START_UP)
    #warning "DEBUG_START_UP is enabled"
#endif

#if (0 == ENABLE_I2C_COMM)
 #warning "I2C is Off"
#endif

#if (0 == USE_PLL)
    #warning "PLL is off"
#endif

#if (1 == DBG_PUTS_EN)
    #warning "puts trace is ON"
#endif

//============== HW Fuses settings ========================
#if(1 == USE_PLL)
    #fuses H4, NOWDT, PUT, NOLVP, NOXINST, FCMEN
    #use delay(clock=40000000)
#elif(0 == USE_PLL)
    #fuses HS, NOWDT, PUT, NOLVP, NOXINST, FCMEN
    #use delay(clock=20000000)
#else
    #error "Out of range"
#endif

#if (3 != __BUILD_TYPE__)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7)
#use i2c(master, sda=PIN_C4, scl=PIN_C3, FORCE_HW, FAST=400000)
//#use i2c(master, sda=PIN_C4, scl=PIN_C3, FORCE_HW, SLOW)
#else
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7)
#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xa0, FORCE_HW)
#endif
//
#define I2C_DISPLAY_ADR (0xa0)  //i2c dyspaly device address
#define I2C_TIMEOUT     (5)     //tryes i2c_write to be ack. when it called with dev address

//#zero_ram

#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <input.c>

#if (2 != __BUILD_TYPE__)
#include "lcdmy.c"
#endif

#include "ms_define.h"

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

#if (2 == __BUILD_TYPE__)
#use fast_io(D)
#use fast_io(E)
#endif

#if (2 == __BUILD_TYPE__)
//++++++++++++++ I/O Ports ++++++++++++++++++
#bit        input_rpm   =   PORTB.7
#bit        input_pos   =   PORTB.6
#bit        input_b5    =   PORTB.5
#bit        input_b4    =   PORTB.4

#bit        led_in      =   PORTC.0

#bit        inject_0    =   LATD.6
#bit        inject_1    =   LATD.7
#bit        buzz        =   LATA.4
#bit        out_coil    =   LATC.1
#bit        en_out_a    =   LATB.7
#bit        en_out_b    =   LATB.6
#elif ((1 == __BUILD_TYPE__) || (3 == __BUILD_TYPE__))
//++++++++++++++ I/O Ports ++++++++++++++++++
#bit        inject_0=           LATB.6
#bit        inject_1=           LATB.7
#bit        input_pos=          PORTB.4
#bit        input_rpm=          PORTB.5
#bit        buzz=               LATA.5
#bit        out_coil=           LATA.4
#else
#error !!! Not defined build !!!
#endif
#define     INJ_OPEN_0          inject_0= 0;
#define     INJ_OPEN_1          inject_1= 0;
#define     INJ_CLOSE           inject_0= 1; inject_1= 1;
#define     COIL_ON             out_coil= 0;
#define     COIL_OFF            out_coil= 1;

#if (1 == USE_PLL)
    #define     RT_TMR_DIV      (T3_DIV_BY_8)
#else
    #define     RT_TMR_DIV      (T3_DIV_BY_4)
#endif

/* trace defines */
#if (1 == TRACE)
    #define TR_POINT (printf("Tp...%u\r\n",++deb_cnt));
#else
    #define TR_POINT
#endif

/* trace defines */
#if (1 == DBG_PUTS_EN)
    #define dbg_puts(x) {puts(x);}
#else
    #define dbg_puts(x) {}
#endif


//============== debug tables ===========================
#if (1 == DEBUG_TABLES)
    #define     REV_D   2500
    #define     MAP_D   200
    #define     BATT_D  132
    #define     COLT_D  350
#endif

#if (1 == RPM_MAP_INDEX)
    #define     ADC_MAP 700
    #define     ADC_BAT 500
#endif

//++++++++++++++++++++++++ timer mode ++++++++++++++++++
#define         SPD     (2)
#define         CYCLE   (4)      //number  pulses to integrate (one cycle on 4 stroke engine) 2 rev.

#if 1 == SPD
    #define     DIV     4e-6
    #define     TDIV    T1_DIV_BY_4
    #define     SCALE   4
#elif 2 == SPD
    #define     DIV     8e-6
    #define     TDIV    T1_DIV_BY_8
    #define     SCALE   8
#else
    #error timer mod error  __LINE__
#endif

#define     TRIGGER_FILTER  (800)       // period in uS - front filter disable TMR1 capture (debounse)
#define     INJ_FLOW        (160)       // cc/min injectotr flow rate - to calculate used fuel
#define     COIL_OFF_TIME   (1500)      //in us whith coili will be in off state
#define     XTAL            (40000000)  // crystal frequency - 40MHz
#define     ICLK            (XTAL/4000) // crystal is divided by four
#define     us_to_tmr1_ticks(x)         ((((x*ICLK)/SCALE)/1000)+1)

//+++++++++++++++++ Start up trigger engine +++++++++++++++++++++++
#define     ENGINE_PRIME_TEMP   (400)
#define     BATT_PRIME_DIFF     (60)

//================== injector calc +++++++++++++++++++++++++++++
                                        // Two injectors work in same time when injector events
#define     time_to_liter(time)        (float)((((float)time*(INJ_FLOW/30))/1000000)/1000)

//================== Igniton env settings ++++++++++++++++++++++++
#define     ms_x_10_to_tmr1_ticks(x)        ((((x * ICLK) / SCALE) / 10) +1)
#define     degr_to_tmr1_ticks(time,deg)    (int16)((time * deg) / 7200)   //convert deg x10 to timer1 ticks
#define     tmr1_ticks_to_degr(time,pulse)  (int16)(((int32)pulse * 7200) / time) //convert timer1 ticks to deg x10
#define     timer_to_rpm(time)              (unsigned int16)(300 * CYCLE / (time * DIV))
#define     adc_to_kpa(adc)             ((int16)((2.4414*adc) + 100))
#define     adc_to_afr(adc)             (int16)((0.147*adc) + 73.5)

//================== env settings +++++++++++++++++++++++++++++
#define     STRING_LENGTH       (4)
#define     SENS_SUPP           (120)               //Supply voltage of sensors X 10
#define     ADC_CONST           (4.375)
#define     ADC_T_COMP          (13.5 * ADC_CONST)  //will use
#define     TEMP_BRIGE          (120)               // resistane of the temp sensor circuit Om
#define     REFRESH_TIME        (2)                 // mS x100
#define     SWAP_DISPLAY_COUNT  (5)                 //counts to swap display view
#define     TIME_INJ_SCALE      (120)               // uS x100
#define     FLASH_BLOCK_SIZE    getenv("FLASH_WRITE_SIZE") //(64)
#define     START_PULSE_CNT     (50)
#define     SECONDS_COUNT_T3    (10)                // timer3 interrupts counter for 1 second
#define     T3_INT_DIV_M        (2)                 // timer3 interrupts counter divider
#define     BATT_MUL            (133.00/33.00)
#define     ADC_CONST_1         (51.00/1023.00)

#define     adc_to_v(adc)       ((int16)((adc * ADC_CONST_1 * BATT_MUL) + 10));

#define     adc_to_r(u, r, adc) ((int16)(adc * ADC_CONST_1) /\
                                    ((u - (adc * ADC_CONST_1)) / r));

//++++++++++++++ Table size +++++++++++++++++++++++++++++++++++
#define     TABLE_STEP          (10)                  //map sensor scale to f-map

//++++++++++++++ MAP settings +++++++++++++++++++++++++++++++++
#define     MAP_MIN             (400)                 //minimum minflod pressure kPa x10
#define     MAP_MAX             (1100)                //maximum minflod pressure kPa x10
#define     MAP_S               ((MAP_MAX-MAP_MIN)/TABLE_STEP)

//++++++++++++++ rev map +++++++++++++++++++++++++++++++++++
#define     REV_MIN             (750)                 //min rpm
#define     REV_MAX             (5500)                //max rpm
#define     REV_S               ((REV_MAX - REV_MIN)/TABLE_STEP)

//++++++++++++++ brake engine mode settings ++++++
#define     REV_MIN_F_CUT       (1450)              //rpm hight than activate brake mode fuel cut
#define     MAP_MIN_F_CUT       (100)               //ka_pa less than MAP_MIN than activate brake mode fuel cut

#if (0 == TMR0_16B)
//+++++++++++++++++++ Injectors settings 8_bit tmr0 mode ++++++++++

#define     TMR_0_P     (64)                                //timer0 prescaler 128!!!
#define     OPEN_TIME   (1000)                              //time to open us
#define     INJ_GO_OPEN ((((OPEN_TIME*ICLK)/TMR_0_P)/1000)+1)
#define     MAX_TMR     (255-INJ_GO_OPEN)
#define     TMR_CONST   ((((1000*ICLK)/TMR_0_P)/1000)+1)    // 10 uS
#define     TST_TIME    (50)                                //full open time in msec
#define     TST_CNT     ((TST_TIME*1000*ICLK)/TMR_0_P)
#define     INIT_TMR    (20)

#else

//+++++++++++++++++++ Injectors settings 16_bit tmr0 mode ++++++++++

#define     TMR_0_P     (4)                                 //timer0 prescaler 128!!!
#define     OPEN_TIME   (1000)                              //time to open us
#define     INJ_GO_OPEN ((((OPEN_TIME*ICLK)/TMR_0_P)/1000)+1)
#define     MAX_TMR     (65535-INJ_GO_OPEN)
#define     TMR_CONST   ((((1000*ICLK)/TMR_0_P)/1000)+1)   // 10 uS

#define     TST_TIME    (60)                                //full open time in sec
#define     TST_CNT     ((TST_TIME*1000*ICLK)/TMR_0_P)
#define     INIT_TMR    (20)

#endif


//+++++++++++++++++++++++++ my defines ==============================
enum adc_en {
#if ((1 ==  __BUILD_TYPE__) || (3 == __BUILD_TYPE__))
    MAP_CH, //tps sensor input - adc chanel 0
    BAT_CH, //batt input - adc chanel 1
    TMP_CH, //temperature sensor input - adc chanel 2
    TPS_CH, //tps sensor input - adc chanel 2
    MAX_CH
#elif(2 ==  __BUILD_TYPE__)
    TPS,            //tps sensor input - adc chanel 0
    WATER_TEMP,     //collant teperature sensor - adc chanel 1
    OIL_PRESS,      //oil pressure sensor input - adc chanel 2
    OIL_TEMP,       //oil temperature - adc chanel 3
    WB_O2_IN,       //lambda sensor input - adc chanel 4
    AIR_TEMP,       //collant teperature sensor - adc chanel 5
    CH_6,           //adc chanel 6
    BATT,           //batt voltage - adc chanel 7
    BAR1,           //air pressure sensor1 - adc chanel 8
    BAR2,           //air pressure sensor1 - adc chanel 9
    MAX_CH
#else
#error !!! Not defined build !!!
#endif
};

enum ign_dbg {
    COUNT_1= 0,
    COUNT_2,
    COUNT_3,
    COUNT_4,
    COUNT_MAX
};

enum view_display {
    NORMAL = 0,     //< 0
    ADC,            //< 1
    IGN_1,          //< 2
    IGN_2,          //< 3
    IGN_3,          //< 4
    KPA,            //< 5
    FUEL_MY,        //< 6
    FUEL,           //< 6
    MAX_DISPLAY = FUEL
};

enum ign_state {
    PULSE_END= 0,
    PULSE_FRONT
};

enum mode_dis {
    MODE_DEF= 1,
    MODE_FUEL,
    MODE_FUEL_NEW
};

#if (1 ==  __BUILD_TYPE__)
unsigned    int8    obt, mapt, barvd, barobd, barob, barv, barinj, inj_ch, bar_p_inj;
unsigned    int8    barinjd, kb_temp, pul, bar_percent, ad_cn_ch, port_b_perv, acc_timer;
unsigned    int8    idx_temp, latb_tmp = 0xF0;
unsigned    int32   time_f, time_r, time_rok, time_fok, time;
unsigned    int16   timeinj, timeinj_crank = 0, oboroti, oborotit, prime_pulse_time;
            int16   diff, deb_time, temp_resistor;
            int1    RST = 0, de_acc, deb_inj, key_hit = 0, ad_ok, inj_sych = 0, cmd_rcv = 0, burn_flag = 0;
            int1    have_i2c_display = 0, refresh_data = 0, prime_pul = 0, ign_power_up = 0;
            int1    timer1_err = 0;
volatile    int1    cranking = 0;
unsigned    int8    pw_acc = 0, pw_acc_tmp = 0, pw_acc_last = 0;
unsigned    int8    pw_acc_tps = 0, pw_acc_map=0;
unsigned    int16   adct, c_p_r, c_p_f, max_baro, k_pa, flow_tst_couter;
unsigned    int16   last_k_pa = 0, last_tps = 0, last_bat = 0;
unsigned    int16   ad_ch[MAX_CH], max_map_adc;
unsigned    int8    rs_string[STRING_LENGTH+1];
unsigned    int8    temp = TMR_CONST;
unsigned    int8    tail_off_step, tail_off_timer = 0, cycles = 0;
unsigned    int8    pw_corr_per_w = 100, pw_corr_per_brk = 100, pw_corr_per = 100;
unsigned    int8    display_mode, freeze_dispaly, pulse_crank = 0;
unsigned    int16   ign_chanel_rise[COUNT_MAX];
unsigned    int16   ign_chanel_fall[COUNT_MAX];
unsigned    int16   offset_ign_chanel[COUNT_MAX];
unsigned    int32   time_1 = 0;
            int16   ign_table_out, ign_timer_in, spark_timer_tick;
            int32   pw_count;
            float   f_count;
            int16   egocount;
#elif(2 ==  __BUILD_TYPE__)
unsigned    int8    obt, mapt, inj_ch;
unsigned    int8    pul, bar_percent, ad_cn_ch, port_b_perv, acc_timer;
unsigned    int8    idx_temp, latb_tmp = 0xF0;
unsigned    int32   time_f, time_r, time_rok, time_fok, time;
unsigned    int16   timeinj, timeinj_crank = 0, oboroti, oborotit, prime_pulse_time;
            int16   diff, temp_resistor;
            int1    RST = 0, de_acc, deb_inj, ad_ok, inj_sych = 0, cmd_rcv = 0, burn_flag = 0;
            int1    have_i2c_display = 0, refresh_data = 0, prime_pul = 0, ign_power_up = 0;
            int1    timer1_err = 0;
volatile    int1    cranking = 0;
volatile    int1    i2c_do_refresh = 0;
unsigned    int8    pw_acc = 0, pw_acc_tmp = 0, pw_acc_last = 0;
unsigned    int8    pw_acc_tps = 0, pw_acc_map=0;
unsigned    int16   c_p_r, c_p_f, max_baro, k_pa, flow_tst_couter = 0;
unsigned    int16   last_k_pa = 0, last_tps = 0, last_bat = 0;
unsigned    int16   ad_ch[MAX_CH], max_map_adc;
unsigned    int8    rs_string[STRING_LENGTH+1];
unsigned    int8    temp = TMR_CONST;
unsigned    int8    tail_off_step, tail_off_timer = 0, cycles = 0;
unsigned    int8    pw_corr_per_w = 100, pw_corr_per_brk = 100, pw_corr_per = 100;
unsigned    int8    display_mode, pulse_crank = 0;
unsigned    int16   ign_chanel_rise[COUNT_MAX];
unsigned    int16   ign_chanel_fall[COUNT_MAX];
unsigned    int16   offset_ign_chanel[COUNT_MAX];
unsigned    int32   time_1 = 0;
            int16   ign_table_out, ign_timer_in, spark_timer_tick;
            int32   pw_count;
            float   f_count;
            int16   egocount;
#elif(3 ==  __BUILD_TYPE__)
unsigned    int8    barvd, barobd, barob, barv, barinj, bar_p_inj;
unsigned    int8    barinjd, kb_temp, pul;
unsigned    int8    latb_tmp = 0xF0;
            int1    RST = 0, key_hit = 0, cmd_rcv = 0, burn_flag = 0;
unsigned    int8    display_mode, freeze_dispaly;
            int1    refresh_data;
int8        *buffer_in, *buffer_out;
int16       address_;

#else
#error !!! Not defined build !!!
#endif

#if (1 == TRACE)
    int8 trace_flag = 0;
#endif

//==================== megasquirt v.1.34 i/o variables (ms_define) =========================
unsigned    char    txmode = 0, rd_wr = 0;
unsigned    int16   txgoal = 0, rxoffset=0, rxnbytes=0, rxcnt=0, txcnt =0;

inputs_t    in_parm;
variables_t out_parm;

#if(2 ==  __BUILD_TYPE__)
#include "data_pack.h"
i2c_data_in_t out;
i2c_data_out_t in;
#endif

#if(3 ==  __BUILD_TYPE__)
#include "data_pack.h"
i2c_data_in_t   in;
i2c_data_out_t  out;
#endif

/* boot loader */
#define     MAX_FLASH getenv("PROGRAM_MEMORY")      //for PICs with 32KB of mem
#define     LOADER_SIZE 0xff                        //tinybld size + a bit more (200 bytes is enough)

#org MAX_FLASH-LOADER_SIZE , MAX_FLASH-1 void boot_loader(void) {}

/* load Hw functions */
#if (3 !=  __BUILD_TYPE__)
#include    "ignition_all.h"
#include    "i2c_sys.h"
#include    "beeper.h"
#include    "inr2d_new.h"
#include    "inter_2d.c"
#include    "uart_comm.h"
#include    "injector_timer.h"
#include    "inj_event.h"
#include    "rt_clk.h"
#include    "adc_chanel.h"
#include    "other_ints.h"
#include    "config_start.h"
#include    "auto_tune.h"
#endif

#if(1 ==  __BUILD_TYPE__)
#include    "dis.h"
#include    "key_read.h"
#include    "set_menu.c"
#include    "display_msg.h"
#elif(2 ==  __BUILD_TYPE__)
#include    "parce_in.h"
#include    "i2c_trasfer.h"
#elif(3 ==  __BUILD_TYPE__)
#include    "dis_i2c.h"
#include    "i2c_isr.h"
#include    "beeper.h"
#include    "key_read.h"
#include    "uart_comm.h"
#include    "rt_clk.h"
#include    "other_ints.h"
#include    "display_msg.h"
#include    "config_start.h"
#else
#error !!! Not defined build !!!
#endif
